package com.lovo;

import java.util.*;

public class Map {
    public static void main(String[] args) {
        Map map = new Map();
        map.Map();
        map.HashMap();

    }

    public void HashMap() {

        java.util.Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "Amy");
        map.put(2, "Joe");
        map.put(3, "Tom");
        map.put(4, "Susan");
        Set set = map.keySet();
        for (Object key : set) {
            System.out.println(key + ":" + map.get(key));
        }
        //要求2
        System.out.println("    ");
        System.out.println("请输入姓名");
        Scanner sc = new Scanner(System.in);
        String name = sc.next();
        map.put(5, name);
        //要求3
        map.remove(4);
        //要求4
        map.replace(3, "Tom", "Tommy");

        //要求5
        Set st = map.keySet();
        for (Object key : st) {
            System.out.println(key + ":" + map.get(key));
        }

    }

    public void Map() {
        String[] arr = {"a", "b", "a", "b", "c", "a", "b", "c", "b"};
        HashMap map = new HashMap();
        List list = Arrays.asList(arr);
        HashSet hashSet = new HashSet();
        hashSet.addAll(list);
//        System.out.println(list);
        List lt = new ArrayList();
        lt.addAll(hashSet);
        int number1 = 0;
        int number2 = 0;
        int number3 = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].equals("a")) {
                number1++;
            } else if (arr[i].equals("b")) {
                number2++;
            } else {
                number3++;
            }
        }
        map.put(lt.get(0), number1);
        map.put(lt.get(1), number2);
        map.put(lt.get(2), number3);
                   Set set = map.keySet();
                   for (Object obj:set)
        System.out.println(obj+":"+map.get(obj));


    }


}

